package com.example.sspulibrary.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sspulibrary.R;

import java.util.List;

/**
 * @author : HengZhang
 * @date : 2022/9/25 16:12
 */

public class SpinnerAdapter extends BaseAdapter {

    Context context;
    List<String> mDatas;


    public SpinnerAdapter() {
    }

    public SpinnerAdapter(Context context, List<String> storeHouse) {
        this.context = context;
        this.mDatas = storeHouse;
        Log.e("SpinnerAdapter", "" + storeHouse.size());
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_spinner, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String data = mDatas.get(position);
        holder.spinnerTv.setText(data);

        return convertView;
    }

    static class ViewHolder {
        TextView spinnerTv;

        public ViewHolder(View view) {
            spinnerTv = view.findViewById(R.id.item_spinner_tv);
        }
    }
}
